/***************************************************************************//**
 * @file MSc_Function.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/
#ifndef MSC_FUNCTION_H
#define MSC_FUNCTION_H

////////////////////////////////////////////////////////////////////////////////

#include <limits>
#include <stddef.h>
#include <vector>

#include "MSc_Argument.h"

////////////////////////////////////////////////////////////////////////////////

/** Math function class. */
class MSc_Function : public MSc_Argument
{
public:

    /** Math operation types enum. */
    enum Operation
    {
        Sum         = 1,    ///< sum
        Difference  = 2,    ///< difference
        Product     = 3,    ///< product
        Quotient    = 4,    ///< quotient
        Power       = 5,    ///< power
        Exponent    = 6,    ///< exponent for basis e
        Absolute    = 7,    ///< absolute value
        Sine        = 8,    ///< sine
        Cosine      = 9,    ///< cosine
        Tangent     = 10,   ///< tangent
        Arcsine     = 11,   ///< arcsine
        Arccosine   = 12,   ///< arccosine
        Arctangent  = 13,   ///< arctangent
        Arctangent2 = 14,   ///< arctangent for the specified coordinates
        Minimum     = 15,   ///< minimum
        Maximum     = 16,   ///< maximum
        Average     = 17    ///< arithmetic mean
    };

    /** Constructor. */
    MSc_Function();

    /** Destructor. */
    virtual ~MSc_Function();

    /**
     * Adds argument to the function's argument list.
     * @param arg argument pointer
     */
    void addArgument( MSc_Argument *arg );

    /**
     * Returns function value.
     * @return function value on success or NaN on failure.
     */
    double getValue() const;

    /** */
    inline bool isValid() const
    {
        return m_argValid;
    }

    /** Sets type of mathematical operation. */
    void setOperation( Operation operation );

private:

    typedef std::vector<MSc_Argument*> Arguments;

    size_t m_argCount;      ///< number of arguments
    bool   m_argValid;      ///< specifies if number of arguments is correct

    Arguments m_arguments;  ///< function arguments
    Operation m_operation;  ///< function operation

    /** Using this constructor is forbidden. */
    MSc_Function( const MSc_Function & ) {}

    /** */
    void check();
};

////////////////////////////////////////////////////////////////////////////////

#endif // MSC_FUNCTION_H
